package com.esri.core.map.popup;

import com.esri.core.internal.util.d;
import com.esri.core.io.EsriServiceException;
import com.esri.core.map.popup.PopupDateFormatValue;
import java.io.StringWriter;
import java.text.ParseException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public abstract class PopupFormatValue {
    private static PopupNumberFormatValue a;
    private static PopupNumberFormatValue b;

    public abstract String formattedValue(Object obj) throws ParseException;

    public static PopupNumberFormatValue getDefaultObjectIDFormatter() {
        PopupNumberFormatValue popupNumberFormatValue = a;
        if (popupNumberFormatValue != null) {
            return popupNumberFormatValue;
        }
        PopupNumberFormatValue popupNumberFormatValue2 = new PopupNumberFormatValue();
        a = popupNumberFormatValue2;
        popupNumberFormatValue2.setDigitSeparator(false);
        return a;
    }

    public static PopupNumberFormatValue getDefaultNumericFormatter() {
        PopupNumberFormatValue popupNumberFormatValue = b;
        if (popupNumberFormatValue != null) {
            return popupNumberFormatValue;
        }
        PopupNumberFormatValue popupNumberFormatValue2 = new PopupNumberFormatValue();
        b = popupNumberFormatValue2;
        return popupNumberFormatValue2;
    }

    public static PopupFormatValue fromJson(JsonParser jsonParser) throws Exception {
        if (!d.c(jsonParser)) {
            throw new EsriServiceException("This response cannot be parsed.");
        }
        PopupNumberFormatValue popupNumberFormatValue = null;
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if ("dateFormat".equals(currentName)) {
                if (popupNumberFormatValue == null) {
                    PopupDateFormatValue.DATE_FORMAT date_format = PopupDateFormatValue.DATE_FORMAT.SHORTDATE;
                    try {
                        date_format = PopupDateFormatValue.DATE_FORMAT.valueOf(jsonParser.getText().toUpperCase());
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    }
                    popupNumberFormatValue = new PopupDateFormatValue(date_format);
                }
            } else if ("places".equals(currentName)) {
                if (popupNumberFormatValue == null) {
                    popupNumberFormatValue = new PopupNumberFormatValue();
                }
                if (jsonParser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
                    popupNumberFormatValue.setPlaces(jsonParser.getIntValue());
                } else if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
                    popupNumberFormatValue.setPlaces(Integer.parseInt(jsonParser.getText()));
                }
            } else if ("digitSeparator".equals(currentName)) {
                if (popupNumberFormatValue == null) {
                    popupNumberFormatValue = new PopupNumberFormatValue();
                }
                if (popupNumberFormatValue instanceof PopupNumberFormatValue) {
                    popupNumberFormatValue.setDigitSeparator(jsonParser.getBooleanValue());
                }
            } else {
                jsonParser.skipChildren();
            }
        }
        return popupNumberFormatValue;
    }

    public String toJson() throws Exception {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a2 = d.a(stringWriter);
        a2.writeStartObject();
        if (this instanceof PopupDateFormatValue) {
            PopupDateFormatValue popupDateFormatValue = (PopupDateFormatValue) this;
            if (popupDateFormatValue.a != null) {
                a2.writeStringField("dateFormat", popupDateFormatValue.b.toString().toLowerCase());
            }
        } else if (this instanceof PopupNumberFormatValue) {
            PopupNumberFormatValue popupNumberFormatValue = (PopupNumberFormatValue) this;
            if (popupNumberFormatValue.a != null) {
                a2.writeNumberField("places", popupNumberFormatValue.getPlaces());
                a2.writeBooleanField("digitSeparator", popupNumberFormatValue.getDigitSeparator());
            }
        }
        a2.writeEndObject();
        a2.close();
        return stringWriter.toString();
    }
}
